home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 230_01 / tests.bun < prev   
Text File  |  1987-05-25  |  46KB  |  2,092 lines

  1. : To unbundle, sh this file
  2. echo unbundling Makefile 1>&2
  3. cat >Makefile <<'End'
  4. .SUFFIXES : .st .test
  5.  
  6. BINDIR = ../bin
  7.  
  8. FILES = Makefile in *.st *.out
  9.  
  10. .st.test:
  11.     $(BINDIR)/st -m $*.st <in | diff - $*.out
  12.  
  13. install:
  14.     echo Performing Self Checking Tests
  15.     -make basic.test
  16.     -make blocks.test
  17.     -make fork.test
  18.     -make new.test
  19.     -make super.test
  20.     -make copy.test
  21.     -make num.test
  22.     -make file.test
  23.     -make primes.test
  24.     -make collect.test
  25.     -make 4queen.test
  26.     echo The following produce cycles, thus have nonzero differences
  27.     -make phil.test
  28.     echo Differences in random numbers may change results in following
  29.     -make sim1.test
  30.     -make sim2.test
  31.     echo Finished Self Checking Tests
  32.     
  33. bundle:
  34.     bundle $(FILES) >../tests.bundle
  35.  
  36. # if the CURSES routines are available, and the form library has been
  37. # built in the /prelude subdirectory (see Makefile there), the following
  38. # executes the plane example
  39. plane:
  40.     $(BINDIR)/st -m -g form plane.st <in
  41.  
  42. # if the PLOT(3) routines are available, and the pen library has been
  43. # built in the /prelude subdirectory (see Makefile there), the following
  44. # executes the pens exame
  45. pen:
  46.     $(BINDIR)/st -m -g pen penshow.st <in
  47. End
  48. echo unbundling in 1>&2
  49. cat >in <<'End'
  50. Main new main
  51. End
  52. echo unbundling 4queen.st 1>&2
  53. cat >4queen.st <<'End'
  54. Class Queen
  55. | myrow mycolumn neighbor boardsize |
  56. [
  57.         build: aQueen col: aNumber size: brdmax
  58.  
  59.                 neighbor <- aQueen.
  60.                 mycolumn <- aNumber.
  61.                 myrow <- 1.
  62.                 boardsize <- brdmax.
  63.                 neighbor first.
  64.                 ^ self
  65.  
  66. |       checkCol: colNumber row: rowNumber      | cd |
  67.                 (rowNumber = myrow) ifTrue: [ ^ false ].
  68.                 cd <- colNumber - mycolumn.
  69.                 ((myrow + cd) = rowNumber) ifTrue: [ ^ false ].
  70.                 ((myrow - cd) = rowNumber) ifTrue: [ ^ false ].
  71.                 (neighbor isNil) ifFalse:
  72.                         [ ^ neighbor checkCol: colNumber row: rowNumber ].
  73.                 ^ true
  74.  
  75. |       first
  76.                 myrow <- 1.
  77.                 ^ self checkrow
  78.  
  79. |       next
  80.                 myrow <- myrow + 1.
  81.                 ^ self checkrow
  82.  
  83. |       checkrow
  84.                 (neighbor isNil) ifTrue: [^ myrow].
  85.                 [myrow <= boardsize] whileTrue:
  86.                         [(neighbor checkCol: mycolumn row: myrow)
  87.                                 ifTrue: [^ myrow]
  88.                                 ifFalse: [myrow <- myrow + 1] ].
  89.                 ((neighbor next) isNil) ifTrue: [^ nil].
  90.                 ^ self first
  91.  
  92. |       printboard
  93.                 (neighbor isNil) ifFalse: [ neighbor printboard].
  94.                 ('Col ', mycolumn asString , ' Row ' ,
  95.                     myrow asString) print
  96. ]
  97.  
  98. Class Main
  99. | lastq |
  100. [
  101.         main | size |
  102.  
  103.                 size <- 4.
  104.                 lastq <- nil.
  105.                 (1 to: size) do: [:x |
  106.                          lastq <- Queen new build: lastq col: x size: size ].
  107.                 lastq first.
  108.                 lastq printboard
  109. ]
  110. End
  111. echo unbundling 8queen.st 1>&2
  112. cat >8queen.st <<'End'
  113. Class Queen
  114. | myrow mycolumn neighbor boardsize |
  115. [
  116.         build: aQueen col: aNumber size: brdmax
  117.  
  118.                 neighbor <- aQueen.
  119.                 mycolumn <- aNumber.
  120.                 myrow <- 1.
  121.                 boardsize <- brdmax.
  122.                 neighbor first.
  123.                 ^ self
  124.  
  125. |       checkCol: colNumber row: rowNumber      | cd |
  126.                 (rowNumber = myrow) ifTrue: [ ^ false ].
  127.                 cd <- colNumber - mycolumn.
  128.                 ((myrow + cd) = rowNumber) ifTrue: [ ^ false ].
  129.                 ((myrow - cd) = rowNumber) ifTrue: [ ^ false ].
  130.                 (neighbor isNil) ifFalse:
  131.                         [ ^ neighbor checkCol: colNumber row: rowNumber ].
  132.                 ^ true
  133.  
  134. |       first
  135.                 myrow <- 1.
  136.                 ^ self checkrow
  137.  
  138. |       next
  139.                 myrow <- myrow + 1.
  140.                 ^ self checkrow
  141.  
  142. |       checkrow
  143.                 (neighbor isNil) ifTrue: [^ myrow].
  144.                 [myrow <= boardsize] whileTrue:
  145.                         [(neighbor checkCol: mycolumn row: myrow)
  146.                                 ifTrue: [^ myrow]
  147.                                 ifFalse: [myrow <- myrow + 1] ].
  148.                 ((neighbor next) isNil) ifTrue: [^ nil].
  149.                 ^ self first
  150.  
  151. |       printboard
  152.                 (neighbor isNil) ifFalse: [ neighbor printboard].
  153.                 ('Col ', mycolumn asString , ' Row ' ,
  154.                     myrow asString) print
  155. ]
  156.  
  157. Class Main
  158. | lastq |
  159. [
  160.         main | size |
  161.  
  162.                 size <- 8.
  163.                 lastq <- nil.
  164.                 (1 to: size) do: [:x |
  165.                          lastq <- Queen new build: lastq col: x size: size ].
  166.                 lastq first.
  167.                 lastq printboard
  168. ]
  169. End
  170. echo unbundling basic.st 1>&2
  171. cat >basic.st <<'End'
  172. Class Main
  173. [
  174.     main
  175.         88 print.
  176.         3.14159 print.
  177.         'this is it' print.
  178.         #(this is also it) print.
  179.         88 respondsTo: #+ ; print.
  180.         Object respondsTo.
  181.         smalltalk at: 3 put: #(22 17).
  182.         (smalltalk at: 3) print.
  183.         Smalltalk respondsTo.
  184. ]
  185. End
  186. echo unbundling blocks.st 1>&2
  187. cat >blocks.st <<'End'
  188. Class Main
  189. [
  190.     main
  191.         (2 < 3) ifTrue: ['correct-1' print].
  192.         ((2 < 3) ifTrue: ['correct-2']) print.
  193.         [:x | x print] value: 'correct-3' .
  194.         ((2 < 3) or: [3 < 4]) ifTrue: ['correct-4' print].
  195.         ((2 > 3) or: [3 < 4]) ifTrue: ['correct-5' print].
  196.         ((2 < 3) and: [3 < 4]) ifTrue: ['correct-6' print].
  197.         ((2 > 3) and: [3 < 4]) ifFalse: ['correct-7' print].
  198.         self test1 print
  199. |
  200.     test1
  201.         self test2: [^ 'correct-8'].
  202.         'should not print' print
  203. |
  204.     test2: aBlock
  205.         self test3: aBlock.
  206.         'should not print' print
  207. |
  208.     test3: bBlock
  209.         bBlock value.
  210.         'should not print' print
  211. ]
  212. End
  213. echo unbundling check.st 1>&2
  214. cat >check.st <<'End'
  215. Class CheckBook
  216. | balance |
  217. [
  218.     new
  219.         balance <- 0
  220. |
  221.     + amount
  222.         balance <- balance + amount.
  223.         ^ balance
  224. |
  225.     - amount
  226.         balance <- balance - amount.
  227.         ^ balance
  228. ]
  229.  
  230. End
  231. echo unbundling collect.st 1>&2
  232. cat >collect.st <<'End'
  233. Class Main
  234. | i |
  235. [
  236.     main
  237.         self test1.
  238.         self test2.
  239.         self test3
  240. |
  241.     test1        | j |
  242.         (i <- 'example') print.
  243.         i size print.
  244.         i asArray print.
  245.         (i occurrencesOf: $e) print.
  246.         i asBag print.
  247.         (j <- i asSet) print.
  248.         j asString reversed print.
  249.         i asDictionary print.
  250.         (j <- i asList) print.
  251.         j addFirst: 2 / 3.
  252.         j addAllLast: (12.5 to: 15 by: 0.75).
  253.         j print.
  254.         j removeLast print.
  255.         (j , #($a 7) ) print.
  256.         (i reject: [:x | x isVowel] ) print.
  257.         (i copyWithout: $e) print.
  258.         i sort print.
  259.         (i sort: [:x :y | y < x]) print.
  260.         i keys print.
  261.         i values print.
  262.         (i atAll: (1 to: 7 by: 2) put: $x) print
  263. |
  264.     test2            | j |
  265.         i <- (1 to: 6) asBag print.
  266.         i size print.
  267.         (i select: [:x | (x \\ 2) strictlyPositive] ) print.
  268.         (j <- (i collect: [:x | x \\ 3]) asSet ) print.
  269.         j size print
  270. |
  271.     test3
  272.         ('bead' at: 1 put: $r) print
  273. ]
  274. End
  275. echo unbundling cond.st 1>&2
  276. cat >cond.st <<'End'
  277. Class Main
  278. [
  279.     main            | i |
  280.         ((2 < 3) ifTrue: ['correct']) print.
  281.         (2 < 3) ifTrue: ['correct' print ].
  282.         i <- 1.
  283.         [i < 3] whileTrue: [i <- i + 1].
  284.         (i >= 3) ifTrue: ['correct' print]
  285. ]
  286.  
  287. End
  288. echo unbundling control.st 1>&2
  289. cat >control.st <<'End'
  290. "
  291.      control the values produced by a generator
  292. "
  293. Class ControlGenerator :Generator
  294. | firstGenerator secondGenerator
  295.   currentFirst currentSecond
  296.   controlBlock computeBlock |
  297. [
  298.         initA: fGen b: sGen control: aBlock compute: anotherBlock
  299.                 firstGenerator <- fGen.
  300.                 secondGenerator <- sGen.
  301.                 controlBlock <- aBlock.
  302.                 computeBlock <- anotherBlock
  303.  
  304. |       first
  305.                 currentFirst <- firstGenerator first.
  306.                 currentSecond <- secondGenerator first.
  307.                 (currentFirst isNil & currentSecond isNil) ifTrue: [^ nil].
  308.                 ^ self controlGeneratorNext
  309.  
  310. |       next
  311.                 ^ self controlGeneratorNext
  312.  
  313. |       controlGeneratorNext    | control returnedValue